from StartProjection import start

import tkinter as tk

def display():
    window = tk.Tk()
    window.title('柱面投影程序')
    window.geometry('500x300')
    # 视频源、焦距
    addres = tk.StringVar()
    addres.set('192.168.1.64')

    user = tk.StringVar()
    user.set('admin')

    password = tk.StringVar()
    password.set('abc123456789')
    
    ratio = tk.IntVar()
    ratio.set(1400)

    # 提示信息
    tk.Label(window, text='用户名:', font=('Arial', 14)).place(x=10, y=90)
    tk.Label(window, text='密码:', font=('Arial', 14)).place(x=10, y=130)
    tk.Label(window, text='地址:', font=('Arial', 14)).place(x=10, y=170)
    tk.Label(window, text='焦距:', font=('Arial', 14)).place(x=10, y=210)
    tk.Label(window, text='Cylindrical Projection', font=('Arial', 16)).pack()

    # 输入窗口
    entry_address = tk.Entry(window, textvariable=user, font=('Arial', 14))
    entry_address.place(x=120, y=95)
    entry_address = tk.Entry(window, textvariable=password, font=('Arial', 14))
    entry_address.place(x=120, y=135)
    entry_address = tk.Entry(window, textvariable=addres, font=('Arial', 14))
    entry_address.place(x=120, y=175)

    entry_ratio = tk.Entry(window, textvariable=ratio, font=('Arial', 14))
    entry_ratio.place(x=120, y=215)

    # 获取输入信息
    def Program_Start():
        ratio_value = ratio.get()
        addres_value = addres.get()
        user_value = user.get()
        password_value = password.get()
        url = "rtsp://%s:%s@%s/live" % (user_value, password_value, addres_value)

        print("开始执行！")
        print("Url: " + url)
        start(url, ratio_value)
        window.quit()
    # 在窗口界面设置放置Button按键
    b = tk.Button(window, text='执行柱面投影', font=('Arial', 12), width=15, height=1, command=Program_Start)
    b.place(x=140, y=250)

    # 第6步，主窗口循环显示
    window.mainloop()

if __name__ == '__main__':
    display()